package com.leyou.page.web;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * @package com.leyou.page.web
 * @description: 加载商品详情页
 * @author: 许超越
 * @date 2019/7/3 14:58
 * @version: V1.0
 */
@Controller
public class PageController {

    @Autowired
    private PageService pageService;

    /**
     * 跳转到商品详情页
     * @param model
     * @param spuId
     * @return
     */
    @GetMapping("item/{id}.html")
    public String queryItemPage(Model model, @PathVariable("id") Long spuId) {
        //查询模型需要的数据
        Map<String, Object> itemData = pageService.queryItemPage(spuId);
        //将数据添加到模型中
        model.addAllAttributes(itemData);
        //跳转页面
        return "item";
    }
}
